<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <script>
    var xmlhttp;
    try {
      xmlhttp = new XMLHttpRequest();
    }catch (e) {
      alert("浏览器不支持AJAX");
    }
    function hello() {
      var url="../HelloServlet?name=" + nm.value();
      //回调函数
      xmlhttp.onreadystatechange = function (){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            res.innerHTML = xmlhttp.responseText;
        }
      }
      xmlhttp.open("get",url);
      xmlhttp.send(null);
    }
  </script>
</head>
<body>
<h1>表单提交</h1>
<form action="../HelloServlet">

  名字：<input name="name">

  <button>Hello</button>
</form>

<h1>AJAX提交</h1>

<form>
  名字：<input name="name" id="nm">
  <button type="button" onclick="hello();">Hello</button>
</form>
<span id ="res"></span>

</body>

</html>